package ru.evga.inse.core.dao.dict.impl;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Repository;

import ru.evga.inse.core.dao.DaoException;
import ru.evga.inse.core.dao.FindRangeContext;
import ru.evga.inse.core.dao.IResultContainer;
import ru.evga.inse.core.dao.dict.ICityDao;
import ru.evga.inse.core.dao.impl.GenericDao;
import ru.evga.inse.core.domain.dict.City;
import ru.evga.inse.core.filter.dict.CityFilter;


@Repository
@Configurable
public class CityDao
    extends GenericDao<City>
    implements ICityDao
{
    public IResultContainer<City> findRange(
        Integer firstResult, 
        Integer maxResults,
        String orderBy, 
        Boolean isAsc, 
        CityFilter filter)
        throws DaoException
    {
        FindRangeContext<City> queryBuilder = new FindRangeContext<City>(this);
        queryBuilder.setOrder(orderBy, isAsc);

        if (filter != null)
        {
            String nameFilter = filter.getName();
            if (nameFilter != null && nameFilter.length() > 0)
            {
                queryBuilder.addLike("name", nameFilter);
            }
        }
        
        return findRange(firstResult, maxResults, queryBuilder);
    }
}
